<?php
namespace app\common\model;
use think\Db;
use think\Model;

class Laxin extends Model
{
    protected $table = 'ds_laxin_free';

    public function getlaxinList($condition, $page = 0, $order = '', $field = '*') {

        if($page) {

            $res = Db::table("ds_laxin_free")->alias("lf")
                ->join('ds_address a','lf.address_id = a.address_id',"left")
                ->join('ds_member m','lf.member_id = m.member_id',"left")

                ->field($field)
                ->where($condition)
                ->order($order)
                ->paginate($page, false, ['query' => request()
                    ->param()]);
            $this->page_info=$res;
            $pintuan_list = $res->items();
            return $pintuan_list;
        }else{
            $res = Db::table("ds_laxin_free")->alias("lf")
                ->join('ds_address a','lf.address_id = a.address_id',"left")
                ->join('ds_member m','lf.member_id = m.member_id',"left")
                ->field($field)
                ->where($condition)
                ->order($order)
                ->select();
            return $res;
        }

    }

    /**
     * 更新拉新活动表数据
     * @param array $condition  更新条件
     * @param array $data       更新数据
     */
    public function updateLaxin($condition = [],$data = [])
    {
        return  Db::table($this->table)->where($condition)->update($data);
    }

    /**
     * 获取拉新订单的总数
     * @param array $condition  查找条件
     */
    public function getLaxinOrderCount($condition = [])
    {
        return  Db::table($this->table)->where($condition)->count();
    }
}